package com.lovo.controller;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.lovo.jwt.CreateJWT;
import com.lovo.utile.dto.UserDto;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @author LiuChengQi
 * @date Created on 2020/12/1
 */
@RestController()
public class PowerController {
//    private static String zyToken;
//    private static String mcToken;
//    static {
//        UserDto zy = new UserDto("zy", "123456");
//        UserDto mc = new UserDto("mc", "123456");
//
//        zyToken = CreateJWT.getToken(zy);
//        mcToken = CreateJWT.getToken(mc);
//
//    }

    @PostMapping("/power")
    public String doPower(@RequestBody UserDto userDto){
        String token = CreateJWT.getToken(userDto);
        DecodedJWT jwt = CreateJWT.verifyToken(token);
        if (jwt.getClaim("userName").asString().equals("zy")
                &&jwt.getClaim("password").asString().equals("123456")) {
            return "login1, login2";
        }
        if (jwt.getClaim("userName").asString().equals("mc")
                &&jwt.getClaim("password").asString().equals("123456")) {
            return "login1, login3";
        }



        return "没权限";
    }
}
